package com.uum.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.uum.admin.pojo.entity.SysMenu;
import com.uum.admin.pojo.entity.SysMenuRole;
import com.uum.admin.mapper.SysMenuRoleMapper;
import com.uum.admin.service.SysMenuRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.uum.web.util.JwtUtils;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Tsang_yc
 * @since 2022-01-16
 */
@Service
@AllArgsConstructor
public class SysMenuRoleServiceImpl extends ServiceImpl<SysMenuRoleMapper, SysMenuRole> implements SysMenuRoleService {



    @Override
    public void saveOrUpdate(Long roleId, List<Long> menuIdList) {
        //先删除角色与菜单关系
        baseMapper.delete(new QueryWrapper<SysMenuRole>().eq("role_id",roleId));

        if (menuIdList.size() == 0) {
            return;
        }

        //保存角色与菜单关系
        for (Long menuId : menuIdList) {
            SysMenuRole menuRole = new SysMenuRole();
            menuRole.setMenuId(menuId);
            menuRole.setRoleId(roleId);
            baseMapper.insert(menuRole);
        }
    }


}
